package com.example.gank.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.List;

public class PageAdapterWithFragment extends FragmentStatePagerAdapter {
    private List<Fragment> fragments;
    private List<String> mFragmentTitles;

    public PageAdapterWithFragment(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    public void setmFragmentTitles(List<String> mFragmentTitles) {
        this.mFragmentTitles = mFragmentTitles;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mFragmentTitles != null && !mFragmentTitles.isEmpty()) {
            return mFragmentTitles.get(position);
        } else {
            return null;
        }
    }

}
